<?php 
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
MYDCONN();
$GLOBALS['MYT']=$GLOBALS['MYD']; ?>
<table width="97%"  border="0" cellpadding="3" cellspacing="1">
  <tr bgcolor="#FBFBFB">
    <td>Referência</td>
    <td width="10%">Cliente</td>
    <td width="12%">Data</td>
    <td width="10%">Estado</td>
    <td width="40%" bgcolor="#FBFBFB">ObservaÇ&otilde;es</td>
    <td width="18%">Requerente</td>
  </tr>
  <?php
	// PROCEDURE
	$QurStatus = ' ccenter_requests.Status IN (1,2,3,4,5,6,9,8,10,11,12,13,14)';
	$QurOffices = '';
	$QurUsers = '';

  if ($_POST['Status'] != '') {
  	$QurStatus = " ccenter_requests.Status = {$_POST['Status']}";
  }
  if ($_POST['Offices'] != '') {
  	$QurStatus = " AND main_offices.ref = {$_POST['Offices']}";
  }
  if ($_POST['Users'] != '') {
  	$QurStatus = " AND main_users.ref = {$_POST['Users']}";
  }
  
  $GET = $GLOBALS['MYD']->db_array("SELECT 
					ccenter_requests.Ref,
					DATE(ccenter_requests.TimeCreated) AS TimeCreated,
					ccenter_requests.Observations,
					main_users.name AS Owner,
					main_offices.name AS Client,
					hcce_status.name AS Status
				FROM ccenter_requests
				INNER JOIN main_users ON main_users.ref = ccenter_requests.RefUser
				INNER JOIN main_offices ON main_offices.ref = ccenter_requests.RefOffice
				INNER JOIN hcce_status ON hcce_status.Ref = ccenter_requests.Status 
				WHERE {$QurStatus}
				AND DATE(TimeCreated) BETWEEN '{$_POST['TimeStart']}' AND '{$_POST['TimeEnd']}'
				{$QurOffices}{$QurUsers}
				ORDER BY ccenter_requests.TimeCreated");
	if (!isset($_GET['ViewRequest']) && !isset($_POST['REF'])) {
	for ($f = 1; $f <= $GET[0]; $f++) { 
	echo '<tr bgcolor="'.gridlines($f).'">
		<td NOWRAP>'; 
		mn_field('button','ED','vwRequest',$GET[$f]['Ref'],'','','','" style="height:22px;margin:1px" onclick="
			idwindow(\'Propriedades do pedidos de Materiais\',\'winreq\',\'winreq\',\'Modules/CentrodeCustos/Lib/frm_requests.php?rqID='.$GET[$f]['Ref'].'\',800,500);');
		echo '</td>
		<td NOWRAP>'.$GET[$f]['Client'].'</td>
		<td NOWRAP>'.$GET[$f]['TimeCreated'].'</td>
		<td NOWRAP>'.$GET[$f]['Status'].'</td>
		<td NOWRAP>'.substr($GET[$f]['Observations'],0,50).'</td>
		<td NOWRAP>'.$GET[$f]['Owner'].'</td>
		</tr>';
  	} 
   } else {
	echo '<tr bgcolor="#FBFBFB">
    <td colspan="6"><a href="'.$GLOBALS['URL'].'Modules/CentrodeCustos/Backoffice/?jB=8">(-) Listagem minimizada</a></td>
  </tr>';
  }
  ?>
</table>
</div>